package com.qy.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

/**
 * 八字信息
 * @author pengt
 *
 */
public class UserEcInfo {
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
    private int year; 
    private int month; 
    private int day; 
    public String gender = "0";
    private boolean leap; 
    Date baseDate = null; 
    final static String chineseNumber[] = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"}; 
    final static String[] Gan = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; 
    final static String[] Zhi = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; 
    static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    final static long[] lunarInfo = new long[]{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, 
        0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 
        0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 
        0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 
        0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 
        0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 
        0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 
        0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, 
        0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 
        0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 
        0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 
        0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 
        0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 
        0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 
        0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 
    }; 
    /** 
     * 六十甲子 
     */ 
    public static final String[] jiazhi = { 
        "甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉", 
        "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰", "辛巳", "壬午", "癸未", 
        "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳", 
        "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯", 
        "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑", 
        "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥" 
    }; 
    /**
     * tengodmap[日干][他干] = 十神
     */
    public String[][] tengodmap = {
    	{"比肩","劫财","食神","伤官","偏财","正财","偏官","正官","偏印","正印"},
    	{"劫财","比肩","伤官","食神","正财","偏财","正官","偏官","正印","偏印"},
    	{"偏印","正印","比肩","劫财","食神","伤官","偏财","正财","偏官","正官"},
    	{"正印","偏印","劫财","比肩","伤官","食神","正财","偏财","正官","偏官"},
    	{"偏官","正官","偏印","正印","比肩","劫财","食神","伤官","偏财","正财"},
    	{"正官","偏官","正印","偏印","劫财","比肩","伤官","食神","正财","偏财"},
    	{"偏财","正财","偏官","正官","偏印","正印","比肩","劫财","食神","伤官"},
    	{"正财","偏财","正官","偏官","正印","偏印","劫财","比肩","伤官","食神"},
    	{"食神","伤官","偏财","正财","偏官","正官","偏印","正印","比肩","劫财"},
    	{"伤官","食神","正财","偏财","正官","偏官","正印","偏印","劫财","比肩"}
    };
    
    /**
     * 五虎遁年起月表（以生月地支对照年干查月干）
     */
    public String[][]  nqy = {
    		{"丙寅","丁卯","戊辰","己巳","庚午","辛未","壬申","癸酉","甲戌","乙亥","丙子","丁丑"},
    		{"戊寅","己卯","庚辰","辛巳","壬午","癸未","甲申","乙酉","丙戌","丁亥","戊子","己丑"},
    		{"庚寅","辛卯","壬辰","癸巳","甲午","乙未","丙申","丁酉","戊戌","己亥","庚子","辛丑"},
    		{"壬寅","癸卯","甲辰","乙巳","丙午","丁未","戊申","己酉","庚戌","辛亥","壬子","癸丑"},
    		{"甲寅","乙卯","丙辰","丁巳","戊午","己未","庚申","辛酉","壬戌","癸亥","甲子","乙丑"}
    };
    /**
     * 五虎遁年起月表（月支）
     */
    public String[] yzlist = {"寅","卯","辰","巳","午","未","申","酉","戌","亥","子","丑"};
    /**
     * 五虎遁年起月表（年干）
     */
    public String[] nglist = {"甲", "己", "乙", "庚", "丙", "辛", "丁", "壬", "戊", "癸"};
    
    /**
     * 十二节
     */
    private String solarTerm = ",小寒,立春 ,惊蛰,清明,立夏,芒种,小暑,立秋,白露,寒露,立冬,大雪,";
    
    private Calendar cal;
    /**
     * 起运时间
     */
    private Calendar startLuck;
    
    /**
     * 年柱
     */
    public String nz;
    /**
     * 日柱
     */
    public String rz;
    /**
     * 月柱
     */
    public String yz;
    /**
     * 时柱
     */
    public String sz;
    
    /**
     * 八字（八个字）
     */
    public String[] eight = new String[8];
    
    /**
     * 4个地支里的藏干
     */
    public String[] four = new String[4];
    
    /**
     * 八字五行属性（八个字）
     */
    public String[] eightElement = new String[8];
    
    /**
     * 八字金木水火土的个数 顺序金木水火土
     */
    public Integer[] elementCount = {0,0,0,0,0};
    /**
     * 干支 五行映射表
     */
    public static Map<String,String> ganzhiMapWuXing = new HashMap<String,String>();
    
    /**
     * 五行生克关系
     * {"某行":"生我|我生|克我|我克"}
     */
    public static Map<String,String> wuXingShengKe = new HashMap<String,String>();
    
    /**
     * 地支藏天干
     */
    public static Map<String,String> dizhiCangGan = new HashMap<String,String>();
    
    //大运顺行还是逆行 默认 顺true
    private boolean asc = true;
   
    
    /**
     * 初始化一些数据
     */
    static{
    	ganzhiMapWuXing.put("甲", "木");
    	ganzhiMapWuXing.put("乙", "木");
    	ganzhiMapWuXing.put("丙", "火");
    	ganzhiMapWuXing.put("丁", "火");
    	ganzhiMapWuXing.put("戊", "土");
    	ganzhiMapWuXing.put("己", "土");
    	ganzhiMapWuXing.put("庚", "金");
    	ganzhiMapWuXing.put("辛", "金");
    	ganzhiMapWuXing.put("壬", "水");
    	ganzhiMapWuXing.put("癸", "水");
    	ganzhiMapWuXing.put("子", "水");
    	ganzhiMapWuXing.put("丑", "土");
    	ganzhiMapWuXing.put("寅", "木");
    	ganzhiMapWuXing.put("卯", "木");
    	ganzhiMapWuXing.put("辰", "土");
    	ganzhiMapWuXing.put("巳", "火");
    	ganzhiMapWuXing.put("午", "火");
    	ganzhiMapWuXing.put("未", "土");
    	ganzhiMapWuXing.put("申", "金");
    	ganzhiMapWuXing.put("酉", "金");
    	ganzhiMapWuXing.put("戌", "土");
    	ganzhiMapWuXing.put("亥", "水");
    	//{"某行":"生我|我生|克我|我克"}
    	wuXingShengKe.put("金", "土|水|火|木");
    	wuXingShengKe.put("木", "水|火|金|土");
    	wuXingShengKe.put("水", "金|木|土|火");
    	wuXingShengKe.put("火", "木|土|水|金");
    	wuXingShengKe.put("土", "火|金|木|水");
    	//地址藏天干
    	dizhiCangGan.put("子", "__癸");
    	dizhiCangGan.put("丑", "癸辛己");
    	dizhiCangGan.put("寅", "甲丙戊");
    	dizhiCangGan.put("卯", "__乙");
    	dizhiCangGan.put("辰", "乙戊癸");
    	dizhiCangGan.put("巳", "庚丙戊");
    	dizhiCangGan.put("午", "丁己");
    	dizhiCangGan.put("未", "乙己丁");
    	dizhiCangGan.put("申", "戊庚壬");
    	dizhiCangGan.put("酉", "__辛");
    	dizhiCangGan.put("戌", "辛丁戊");
    	dizhiCangGan.put("亥", "_甲壬");
    }
  
    private String getYearGanZhi(int hour) {
    	//不存在就设为1 子时  13 也设为子时
    	if((hour == 0) || (hour == 13)){
    		hour = 1;
    	}
        //1864年是甲子年，每隔六十年一个甲子 
        int idx = (year - 1864) % 60; 
        //String y = jiazhi[idx]; 年份的干支 ,实际应还与月日有关，立春前出生应为上一年的。
        List<String> list = SolarTerm.yearlClist; //1900-2020立春列表
        String nextlc = list.get(year-1900+1); //year 后一年的立春时间
        String t = year + "" + ((month>9)?month:("0"+month)) + "" + ((day>9)?day:("0"+day));
        if(Integer.parseInt(t) > Integer.parseInt(nextlc)){ //下一年春分后出生 为下一个甲子了
        	idx++;
        }
        String y = jiazhi[idx];
        
        String m=""; 
        String d=""; 
        String h=""; 
        idx = idx % 5; 

        /** 
         * 年上起月 
         * 甲己之年丙作首，乙庚之岁戊为头， 
         * 丙辛必定寻庚起，丁壬壬位顺行流， 
         * 更有戊癸何方觅，甲寅之上好追求。 
         */ 
		SolarTerm st = new SolarTerm();
        String _yzstr = st.getYZ(cal);
        int _yzidx = 0;
        for(int k=0;k<this.yzlist.length;k++){
        	if(_yzstr.equals(this.yzlist[k])){
        		_yzidx = k;
        		break;
        	}
        }
        int _ngidx = 0;
        for(int j=0;j<this.nglist.length;j++){
        	if(y.subSequence(0, 1).equals(this.nglist[j])){
        		_ngidx = j;
        	}
        }
        m = this.nqy[_ngidx/2][_yzidx];
        
         
        /*求出和1900年1月31日甲辰日相差的天数 
         * 甲辰日是第四十天 
        */ 
        int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()  + 3600000L) / 86400000L); 
        offset=(offset+40)%60; 
        //求的日的干支 
        d=jiazhi[offset]; 
         
        /** 
         * 日上起时 
         * 甲己还生甲，乙庚丙作初， 
         * 丙辛从戊起，丁壬庚子居， 
         * 戊癸何方发，壬子是真途。   
         */ 
         
        offset=(offset % 5 )*2; 
        //求得时辰的干支    
        h=Gan[(offset+hour-1)%10]+Zhi[hour-1]; 
        //在此处输出我们的年月日时的天干地支 
        this.nz = y;
        this.yz = m;
        this.rz = d;
        this.sz = h;
        this.eight[0] = y.substring(0,1);
        this.eight[1] = y.substring(1,2);
        this.eight[2] = m.substring(0,1);
        this.eight[3] = m.substring(1,2);
        this.eight[4] = d.substring(0,1);
        this.eight[5] = d.substring(1,2);
        this.eight[6] = h.substring(0,1);
        this.eight[7] = h.substring(1,2);
        
        this.four[0] = dizhiCangGan.get(eight[1]);
        this.four[1] = dizhiCangGan.get(eight[3]);
        this.four[2] = dizhiCangGan.get(eight[5]);
        this.four[3] = dizhiCangGan.get(eight[7]);
        
        /**
         * 计算八字五行的个数
         */
        for(int i=0;i<8;i++){
        	String element = ganzhiMapWuXing.get(this.eight[i]);
        	if(element.equals("金")){
        		this.elementCount[0]++;
        	}else if(element.equals("木")){
        		this.elementCount[1]++;
        	}else if(element.equals("水")){
        		this.elementCount[2]++;
        	}else if(element.equals("火")){
        		this.elementCount[3]++;
        	}else if(element.equals("土")){
        		this.elementCount[4]++;
        	}
        }
        return y+m+d+h; 
    }
   
    /**
     * 计算出时辰序号
     * "子：1", "丑：2", "寅：3", "卯：4", "辰：5", "巳：6", "午：7", "未：8", "申：9", "酉：10", "戌：11", "亥：12" 
     * @param cal2
     * @return
     */
    private int getDZHour() {
    	int hour = this.cal.get(Calendar.HOUR_OF_DAY);
    	if(hour == 24){
    		hour = 0;
    	}
    	String index = "子丑寅卯辰巳午未申酉戌亥"; //时辰顺序
    	String time = "子丑丑寅寅卯卯辰辰巳巳午午未未申申酉酉戌戌亥亥子"; //24小时对应的时辰
    	String t = time.substring(hour, hour+1);
		return index.indexOf(t)+1;
	}
    
//====== 传回农历 y年的总天数

    final public static int yearDays(int y) { 
        int i, sum = 348; 
        for (i = 0x8000; i > 0x8; i >>= 1) { 
            if ((lunarInfo[y - 1900] & i) != 0) { 
                sum += 1; 
            } 
        } 
        return (sum + leapDays(y)); 
    }

//====== 传回农历 y年闰月的天数 
    final public static int leapDays(int y) { 
        if (leapMonth(y) != 0) { 
            if ((lunarInfo[y - 1900] & 0x10000) != 0) { 
                return 30; 
            } else { 
                return 29; 
            } 
        } else { 
            return 0; 
        } 
    }

//====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0 
    final public static int leapMonth(int y) { 
        return (int) (lunarInfo[y - 1900] & 0xf); 
    }

//====== 传回农历 y年m月的总天数 
    final public static int monthDays(int y, int m) { 
        if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0) { 
            return 29; 
        } else { 
            return 30; 
        } 
    }

/*** 
* @return 传回农历 y年的生肖 
*/ 
    final public String animalsYear() { 
        final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}; 
        return Animals[(year - 4) % 12]; 
    }

//====== 传入 月日的offset 传回干支, 0=甲子 
    final private static String cyclicalm(int num) { 
        return (Gan[num % 10] + Zhi[num % 12]); 
    }

//====== 传入 offset 传回干支, 0=甲子 
    final public String cyclical() { 
        int num = year - 1900 + 36; 
        return (cyclicalm(num)); 
    }

    /**
     * 计算农历生日
     */
    public void calculateLunarCalendar(){
    	 int monCyl; 
         int leapMonth = 0; 
          
         try { 
             baseDate = chineseDateFormat.parse("1900-1-31"); 
         } catch (ParseException e) { 
             e.printStackTrace(); //To change body of catch statement use Options | File Templates.

         }

 //求出和1900年1月31日相差的天数 
         int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L); 
         monCyl = 14;

 //用offset减去每农历年的天数 
 // 计算当天是农历第几天 
 //i最终结果是农历的年份 
 //offset是当年的第几天 
         int iYear, daysOfYear = 0; 
         for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) { 
             daysOfYear = yearDays(iYear); 
             offset -= daysOfYear; 
             monCyl += 12; 
         } 
         if (offset < 0) { 
             offset += daysOfYear; 
             iYear--; 
             monCyl -= 12; 
         } 
 //农历年份 
         year = iYear;

         leapMonth = leapMonth(iYear); //闰哪个月,1-12

         leap = false;

 //用当年的天数offset,逐个减去每月（农历）的天数，求出当天是本月的第几天 
         int iMonth, daysOfMonth = 0; 
         for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) { 
 //闰月 
             if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) { 
                 --iMonth; 
                 leap = true; 
                 daysOfMonth = leapDays(year); 
             } else { 
                 daysOfMonth = monthDays(year, iMonth); 
             } 
             offset -= daysOfMonth; 
 //解除闰月 
             if (leap && iMonth == (leapMonth + 1)) { 
                 leap = false; 
             } 
             if (!leap) { 
                 monCyl++; 
             } 
         } 
 //offset为0时，并且刚才计算的月份是闰月，要校正 
         if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) { 
             if (leap) { 
                 leap = false; 
             } else { 
                 leap = true; 
                 --iMonth; 
                 --monCyl; 
             } 
         } 
 //offset小于0时，也要校正 
         if (offset < 0) { 
             offset += daysOfMonth; 
             --iMonth; 
             --monCyl; 
         } 
         month = iMonth; 
         day = offset + 1; 
    }
    /** 
     * 传出y年m月d日对应的农历. 
     * yearCyl3:农历年与1864的相差数 ? 
     * monCyl4:从1900年1月31日以来,闰月数 
     * dayCyl5:与1900年1月31日相差的天数,再加40 ? 
     * 
     * @param cal 
     * @return 
     */ 
    public UserEcInfo(String nian,String yue,String ri,String shi) {
    	Calendar cal = Calendar.getInstance(); 
        try {
			cal.setTime(sdf.parse(nian+"-"+((yue.length()==1)?("0"+yue):yue)+"-"+((ri.length()==1)?("0"+ri):ri)+" "+((shi.length()==1)?("0"+shi):shi)+":00"));
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
        this.cal=cal; 
        calculateLunarCalendar();
        getYearGanZhi(getDZHour()) ;
    }

    
    public static String getChinaDayString(int day) { 
        String chineseTen[] = {"初", "十", "廿", "卅"}; 
        int n = day % 10 == 0 ? 9 : day % 10 - 1; 
        if (day > 30) { 
            return ""; 
        } 
        if (day == 10) { 
            return "初十"; 
        } else { 
            return chineseTen[day / 10] + chineseNumber[n]; 
        } 
    }

    public String getLunarCalendar() { 
        return getYearStr(year) + "年" + (leap ? "闰" : "") + chineseNumber[month - 1] + "月" + getChinaDayString(day); 
    }

    public String getYearStr(int year) { 
        String[] chineseword = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}; 
        String ys = ""; 
        int index = year / 1000; 
        ys += chineseword[index]; 
        year = year % 1000; 
        index = year / 100; 
        ys += chineseword[index]; 
        year = year % 100; 
        index = year / 10; 
        ys += chineseword[index]; 
        year = year % 10; 
        index = year; 
        ys += chineseword[index]; 
        return ys; 
    }

    public static String getSixtyDay() {

        String temp = ""; 
        for (int i = 0; i < 60; i++) { 
            temp += ",\"" + cyclicalm(i) + "\""; 
        } 
        return temp; 
    } 
    
    /**
     * 排大运
     * @return
     */
    public String fate(){
    	String year = "甲丙戊庚壬"; //阳 
    	String ng = "";//年干
    	String yz = this.yz;//月住
    	String ret = "";
    	int p = 0; //月住在六十甲子中的位置
    	ng = this.nz.substring(0, 1);
    	if(year.indexOf(ng) >= 0){ //阳男阴女顺排
    		if(gender.equals("1")){
    			asc = true;
    		}else{
    			asc = false;
    		}
    	}else{
    		if(gender.equals("1")){
    			asc = false;
    		}else{
    			asc = true;
    		}
    	}
    	for(int i=0;i<jiazhi.length;i++){
    		if(jiazhi[i].equals(yz)){
    			p = i;
    		}
    	}
    	//顺排
    	if(asc){
    		for(int i=0;i<8;i++){
    			if(p == jiazhi.length-1){
    				p = -1;
    			}
    			ret += jiazhi[p+1] + " ";
    			p++;
    		}
    	}else{ //倒排
    		for(int i=0;i<8;i++){
    			if(p == 0){
    				p = jiazhi.length;
    			}
    			ret += jiazhi[p-1] + " ";
    			p--;
    		}
    	}
    	return ret;
    }
    /**
     * 起运时间
     * 大运数的起法, 以三天折合一岁计, 即一天折合四个月, 一小时折合五天
     * @return
     */
    public String startLuckTime(){
    	Calendar birth = (Calendar)this.cal.clone(); //出生日期
    	SolarTerm st = new SolarTerm();
    	while(st.getSoralTerm(birth.getTime()).equals("") || solarTerm.indexOf(st.getSoralTerm(birth.getTime())) < 0){
    		birth.add(Calendar.DAY_OF_MONTH, asc?1:-1);
    	}
    	long t1 = birth.getTimeInMillis();
    	long t2 = this.cal.getTimeInMillis();
    	//出生日期与最近节气的日期差
    	Long sub = Math.abs(t1 - t2)/(24*60*60*1000); 
    	//出生日期与最近节气的日期差 * 120 得出起运时间
    	Long time = sub * 120;
    	//出生后xx天伟起运时间
    	birth.add(Calendar.DAY_OF_MONTH, time.intValue());
    	this.startLuck = birth;
    	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    	String dateStr = df.format(birth.getTime());
    	return dateStr;
    }
    
    /**
     * 起运岁数
     * @return
     */
    public int startLuckAge(){
    	this.startLuckTime();
    	return this.startLuck.get(Calendar.YEAR) - this.cal.get(Calendar.YEAR);
    }
    
    /**
     * 交运年份列表
     * @return
     */
    public List<String> startFloatLuckYear(){
    	List<String> ret = new ArrayList<String>();
    	for(int i=this.startLuckAge(),j=0;j<8;i+=10,j++){
    		ret.add(String.valueOf(i));
    	}
    	return ret;
    }
   
    /**
     * 八字强弱
     * (不准确，待修改)
     * @return
     */
    public String strongweak(){
    	//日干
    	String rigan = this.eight[4];
    	//日干五行
    	String day_element = this.ganzhiMapWuXing.get(rigan);
    	double point[] = {0.5,0.5,1.5,4,0,2,1,0.5}; //各干支所占比例
    	double ret = 0; //最后得分 大于0 则强
    	for(int i=0;i<this.eight.length;i++){
    		String e = ganzhiMapWuXing.get(eight[i]); //得出某干支属性
    		this.eightElement[i] = e;
    		String elements[] = wuXingShengKe.get(day_element).split("[|]");
    		if(e.equals(elements[0])){
    			ret =+ point[i];
    		}
    		if(e.equals(elements[2])){
    			ret =- point[i];
    		}
    	}
    	if(ret == 0){
    		return "平";
    	}
    	return ret>0?"强":"弱";
    }
    /**
     * 十神
     * @return
     */
    public List<String> getTenGod(){
    	List<String> ret = new ArrayList<String>();
    	//日干
    	String rg = this.eight[4];
    	String gan = "甲乙丙丁戊己庚辛壬癸";
    	int index = gan.indexOf(rg);
    	//年、月、时对应的3个十神
    	int y_index = gan.indexOf(this.eight[0]);
    	int m_index = gan.indexOf(this.eight[2]);
    	int h_index = gan.indexOf(this.eight[6]);
    	ret.add(this.tengodmap[index][y_index]);
    	ret.add(this.tengodmap[index][m_index]);
    	ret.add(this.tengodmap[index][h_index]);
    	
    	//地藏干 
    	String dcg = "";
    	for(int i=0;i<this.four.length;i++){
    		dcg += this.four[i];
    	}
    	for(int j=0;j<dcg.length();j++){
    		int k = gan.indexOf(dcg.substring(j, j+1));
    		if(k == -1){ //地藏干有3个位置，如果为空，那么十神对应也写空
    			ret.add("_");
    		}else{
    			ret.add(this.tengodmap[index][k]);
    		}
    	}
    	return ret;
    }
    public void resetTime(String t){
    	
    }
    /** 
     * 针对一个在西元 1983-01-10 中午12：30生的人的计算。 
     * 这里12点半在中国的古代历书中算是午时 
     * 子时23.00－1.00,丑时1.00－3.00,寅时3.00－5.00,卯时5.00－7.00, 
     * 辰时7.00－9.00,巳时9.00－11.00,午时11.00－13.00,未时13.00－15.00 
     * 申时15.00－17.00,酉时17.00－19.00,戌时19.00－21.00,亥时21.00－23.00 
     * */ 
    public static void main(String[] args){ 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
        try { 
                //设定此人的西元时间为1983-01-10 
        		UserEcInfo lunar = new UserEcInfo("1985","10","8","8"); 
                //System.out.println("农历的日期【"+lunar.getLunarCalendar()+"】"); 
                //此处是为了获取时间在中国的八字学说上的显示，此人是午时生的 
                //System.out.println("此人八字【"+StringUtils.join(lunar.eight,"")+"】"); 
                
                //System.out.println("地支藏干【"+lunar.dizhiCangGan.get(lunar.eight[1])+"  "+lunar.dizhiCangGan.get(lunar.eight[3])+"  "+lunar.dizhiCangGan.get(lunar.eight[5])+"  "+lunar.dizhiCangGan.get(lunar.eight[7])+"】"); 
                //System.out.println("十神【"+lunar.getTenGod() +"】"); 
                //System.out.println("年柱【"+lunar.nz+"】");
                //System.out.println("月柱【"+lunar.yz+"】");
                //System.out.println("日柱【"+lunar.rz+"】");
                //System.out.println("时柱【"+lunar.sz+"】");
                //System.out.println("日干【"+lunar.rz.substring(0, 1)+"】");
                //System.out.println("日干五行【"+lunar.ganzhiMapWuXing.get(lunar.eight[4])+"】");
                //System.out.println("八字五行个数【"+ StringUtils.join(lunar.elementCount,",")+"】");
                //System.out.println("八字强弱【"+lunar.strongweak()+"】");
                //System.out.println("此人大运【"+lunar.fate()+"】"); 
                //System.out.println("此人起运时间【"+lunar.startLuckTime()+"】"); 
                //System.out.println("此人起运岁数【"+lunar.startLuckAge()+"】"); 
                String y[] = new String[lunar.startFloatLuckYear().size()];
                y = lunar.startFloatLuckYear().toArray(y);
                //System.out.println("交运年份【"+StringUtils.join(y,",")+"】"); 
                //System.out.println("格局【"+"xxxx"+"】"); 
                //获取生肖 
                //System.out.println("此人的农历生肖【"+lunar.animalsYear()+"】");

        }catch(Exception e){ 
            e.printStackTrace(); 
        } 
    }

	public String[] getEight() {
		return eight;
	}

	public void setEight(String[] eight) {
		this.eight = eight;
	}

	public String[] getFour() {
		return four;
	}

	public void setFour(String[] four) {
		this.four = four;
	} 
    
}
